<!doctype html>
<html>
<head>
    <title>模拟购物车加减</title>
    <meta charset="utf-8">
    <script src="../angular.js"></script>
</head>
<body ng-app="goods">
    <div ng-controller="ctrl">
        商品名: {{goods.data.title}} <br />
        商品价格: {{goods.data.price}} <br />
        商品数量 ： {{goods.data.num}} <br />
        <button type="button" ng-click="goods.add()">增加</button>
        <button type="button" ng-click="goods.reduce()">减少</button><br />
        总计 : {{goods.data.price * goods.data.num}}

    </div>

<script>
    var mod = angular.module('goods', []);
    mod.controller('ctrl', ['$scope', function ($scope) {
        $scope.goods = {
            data : {"title" : "小米6", "price" : '2499', "num" : 0},
            add : function () {
                $scope.goods.data.num = Math.min( ++$scope.goods.data.num, 6);
            },
            reduce : function () {
                $scope.goods.data.num = Math.max( --$scope.goods.data.num, 0);
            }
        }
    }]);
</script>
</body>
</html>